﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.UI;

public class CollideSystem
{
    private static Entity curEntity;
    private static void ForeachEntity(Entity entity)
    {
        curEntity = entity;
        GameMgr.Instance().ForeachEntity(CollideSystem.CheckCollide);

    }

    private static void CheckCollide(Entity entity)
    {
        if (curEntity == entity)
        {
            return;
        }

        int distance = (int)(Mathf.Sqrt((curEntity.position.pos- entity.position.pos).sqrMagnitude));

        if (distance < entity.collider.radius+ curEntity.collider.radius)
        {
            //Debug.Log("碰撞发生 distance2:" + distance);

            Vector3 dir = (entity.position.pos - curEntity.position.pos);
            entity.push = new PushMe();
            entity.push.rotaion = (int)(Mathf.Atan2(dir.x, dir.z)/Mathf.PI*180);
            entity.push.index = 0;
            entity.push.lineSpeed = new int[] {60,60,60,55,55,50,45,40,35,30,25 };
        }
    }

    public static void Action()
    {
        GameMgr.Instance().ForeachEntity(CollideSystem.ForeachEntity);
    }
}
